package com.byinsight.web.actions.security;

import com.byinsight.web.actions.BaseAction;
import com.byinsight.web.actions.ErrorCode;
import com.byinsight.web.actions.WebException;
import com.byinsight.web.actions.util.UserTokenEncoder;

import eg.backend.domain.User;

public class LogonAction extends BaseAction {
	private static final long serialVersionUID = -383706243858582449L;
		
	private String username;
	private String password;
	
	@Override
	protected String process() {
		User user = userManager.logonUser(username, password);
		if (null == user) {
			WebException e = new WebException(ErrorCode.LOGON_FAIL);
			throw e;
		}		
		return UserTokenEncoder.encode(user);
	}

	/* struts */	
	public void setPassword(String password) {
		this.password = password;
	}

	public void setUsername(String username) {
		this.username = username;
	}

}
